/**
 * 
 */
$(function(){
	var arrinput=document.getElementsByTagName('input');
	//商品总金额
	var zje=document.getElementById('total_account');
	//商品总共优惠的钱
	var yhe=document.getElementById('total_economy');
	//通过类选择器获取每本书的单价数组
	var arrprice=document.getElementsByClassName('price_dan');
	//通过类选择器获取每本书的数量数组
	var arrnum=document.getElementsByClassName('buy_td_1');
	var sum=0;
	for(var i=0;i<arrinput.length;i++){
		arrinput[i].onblur=function(){
			var a=this.nextElementSibling;
			if(this.value==""){
				alert("变更数量不能为空");
			}else{
			if(this.value>=0){
				a.setAttribute('href',this.nextElementSibling.href+this.value);
			}else{
				var str=this.parentNode.previousElementSibling.innerHTML;
				var num=parseInt(this.parentNode.previousElementSibling.innerHTML.substring(str.lastIndexOf(";")+1,str.length));
				if((num+parseInt(this.value))<1){
					alert("变更数量超过当前数量");
				}else{
					a.setAttribute('href',this.nextElementSibling.href+this.value);
				}
			}
			
			
		}
	}
		
	}
	
	for(var i=0;i<arrprice.length;i++){
		//获取每本书的价格,带$符号
		var price=arrprice[i].innerText;
		price=price.substring(price.lastIndexOf("￥")+1);
		sum=sum+price*arrnum[i+2].innerText;
	}
	zje.innerText=sum;
});